package com.example.home.attorney.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.attorney.ServiceModeFragment;
import com.example.home.attorney.UserEvaluateFragment;
import com.example.home.attorney.adapter.HotAttorneyTabAdapter;
import com.example.home.attorney.bean.HotAttorneyBean;
import com.example.home.attorney.bean.SearchResult;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;

import static com.example.home.tool.StaticActi.ip;

public class ConsultActivity extends AppCompatActivity {

    public static HotAttorneyBean.DataBean conuslt;

    private ImageView imgUrl;
    private TextView name;
    private TextView workStartAt;
    private TextView serviceTimes;
    private TextView legalExpertiseName;
    private TabLayout tabList;
    private ImageView back;

    private ViewPager viewPager;
    private SearchResult rcvListBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consult);
        Intent intent = getIntent();

        Gson gson = new Gson();
        String consultJson = intent.getStringExtra("conuslt");
        conuslt = gson.fromJson(consultJson, HotAttorneyBean.DataBean.class);


        initView();
        //律师基本信息
        getHeadData();
        getTabList();

    }



    private void getTabList() {
        tabList = findViewById(R.id.tab_list);
        viewPager = findViewById(R.id.viewPager);

        // 使用之前从Intent中解析得到的conuslt对象
        HotAttorneyBean.DataBean conuslt = ConsultActivity.conuslt;

        UserEvaluateFragment userEvaluateFragment = new UserEvaluateFragment(conuslt);
        ServiceModeFragment serviceModeFragment = new ServiceModeFragment(conuslt);
        HotAttorneyTabAdapter hotAttorAdapter = new HotAttorneyTabAdapter(getSupportFragmentManager());
        hotAttorAdapter.addFragment(serviceModeFragment, "服务方式");
        hotAttorAdapter.addFragment(userEvaluateFragment, "用户评价");
        viewPager.setAdapter(hotAttorAdapter);
        tabList.setupWithViewPager(viewPager);
    }


    private void getHeadData() {
        Glide.with(ConsultActivity.this).load(ip+conuslt.getAvatarUrl()).into(imgUrl);
        name.setText(conuslt.getName());
        workStartAt.setText(conuslt.getLegalExpertiseName());
        serviceTimes.setText("咨询人数:"+conuslt.getFavorableCount());
        legalExpertiseName.setText("服务次数:"+conuslt.getServiceTimes());

    }

    private void initView() {

        back = findViewById(R.id.back);
        imgUrl = findViewById(R.id.imgUrl);
        name = findViewById(R.id.name);
        workStartAt = findViewById(R.id.workStartAt);
        serviceTimes = findViewById(R.id.serviceTimes);
        legalExpertiseName = findViewById(R.id.legalExpertiseName);


        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ConsultActivity.this.finish();
            }
        });
    }
}